package cn.ybk.user.dto;

import cn.ybk.basic.util.MD5Utils;
import cn.ybk.basic.util.StrUtils;
import cn.ybk.user.domain.User;
import lombok.Data;

import javax.validation.constraints.NotBlank;
import java.util.Date;

@Data
public class WechatBinderDto {
    @NotBlank(message = "手机号不能为空")
    private String phone;
    @NotBlank(message = "手机验证码不能为空")
    private String verifyCode;
    @NotBlank(message = "token不能为空")
    private String accessToken;
    @NotBlank(message = "微信唯一标识符不能为空")
    private String openId;

    // 构造一个user
    public User getUser() {
        String password = "1";
        String salt = StrUtils.getComplexRandomString(32);
        String pwd = MD5Utils.encrypByMd5(salt + password);

        return User
                .builder()
                .phone(this.phone)
                .createtime(new Date())
                .username("微信绑定")
                .state(1)
                .password(pwd)
                .salt(salt)
                .build();
    }
}
